﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using MCWEBSITE.BUL;
using MCWEBSITE.ENTITY;

public partial class Modules_WebsiteFrontSub_wucProductList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string CatID;
            if (Request.QueryString["CatID"] != null)
            {
                CatID = Request.QueryString["CatID"].ToString();
            }
            else
            {
                CatID = "0";
            }

            this.FillData(Convert.ToInt32(CatID));
        }
    }

    protected void FillData(int CatID)
    {
        string Language = "vi-VN";
        try
        {
            Language = Session["LanguageCode"].ToString();
        }
        catch (Exception ex)
        {
            throw ex;
        }

        List<websiteProductInfo> lstwebsiteProductInfo1 = new List<websiteProductInfo>();
        websiteProductCategoryInfo objCategory = new websiteProductCategoryInfo();
        if (CatID != 0)
        {
            lstwebsiteProductInfo1 = websiteProductBUL.GetByLanguageAndCategoryDS(CatID, "1", Language);
            objCategory = websiteProductCategoryBUL.Load(CatID);
            lblCatName.Text = objCategory.CategoryName;
        }
        else
        {
            lstwebsiteProductInfo1 = websiteProductBUL.SelectNtoMByLanguage(1, 8, "1", Language);
            lblCatName.Text = "Sản phẩm";
        }

        foreach (websiteProductInfo obj in lstwebsiteProductInfo1)
        {
            string fileName = "";
            DirectoryInfo ThumbDirectory = new DirectoryInfo(Server.MapPath(obj.Image));
            foreach (FileInfo file in ThumbDirectory.GetFiles())
            {
                if (file.Name != "vssver2.scc" && file.Name != "Thumbs.db")
                    fileName = file.Name.ToString();
            }
            obj.Image += fileName;
            if (obj.Description.Length >= 20)
                obj.Description = obj.Description.Substring(0, 20) + " ...";
        }
        dlProduct.DataSource = lstwebsiteProductInfo1;
        dlProduct.DataBind();
    }

    public string ConvertString(string strThumb)
    {
        if (strThumb != "")
            return strThumb.Remove(0, 2);
        return strThumb;
    }
}
